						
package com.module.device.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import base.util.Page;

import com.activityClient.util.PropertiesUtil;
import com.module.device.manager.DeviceActiveStatusManager;
import com.module.device.vo.DeviceActiveStatus;

public class DeviceActiveStatusService {

	public Page list(DeviceActiveStatus bean, Integer start, Integer limit)
			throws Exception {
		Page page = new Page();
		page.setStart(start);
		page.setLimit(limit);
		//bean.setUserId(LoginSession.getUserid());
		DeviceActiveStatusManager manager = DeviceActiveStatusManager.getInstance();
		page = manager.list(page, bean);
		return page;
	}

	public Map<String,Object> remove(Long id)throws Exception{       
		Map<String,Object> map = new HashMap<String,Object>();
		DeviceActiveStatusManager manager = DeviceActiveStatusManager.getInstance();
		map = manager.delete(id);
		return map;
		
	}	


	public Map<String,Object> save(DeviceActiveStatus bean)throws Exception{
		//bean.setOrgId(LoginSession.getOrgid());
		Map<String,Object> map = new HashMap<String,Object>();
		DeviceActiveStatusManager manager = DeviceActiveStatusManager.getInstance();
		map = manager.add(bean);
		return map;

	} 
	

	public DeviceActiveStatus findById(Long id)throws Exception{
		DeviceActiveStatus bean = new DeviceActiveStatus();
		DeviceActiveStatusManager manager = DeviceActiveStatusManager.getInstance();
		bean = manager.findById(id);
		return bean;
	}
	public DeviceActiveStatus findeBySoftwareCode(String softwarecode)throws Exception{
		DeviceActiveStatus bean = new DeviceActiveStatus();
		DeviceActiveStatusManager manager = DeviceActiveStatusManager.getInstance();
		List list =manager.findBysoftwareCode(softwarecode);
		if(list!=null&&!list.isEmpty()){
		bean = (DeviceActiveStatus) list.get(0);
		}
		int activetime = Integer.parseInt(PropertiesUtil.getString("activetime"));
		float isActive=(System.currentTimeMillis()-bean.getUpdatetime().getTime())/60000;
		if(isActive<activetime)
		{
			bean.setActiveStatus("活跃");
		}else
		{
			bean.setActiveStatus("不活跃");
		}
		return bean;
	}	
	
	public static void main(String args[]) throws Exception
	{
		DeviceActiveStatusService das = new DeviceActiveStatusService();
		das.findeBySoftwareCode("00851");
	}
	
	
}
